package center

import (
	"encoding/json"
	"io/ioutil"
)

const (
	config_file = "config.json"
)

var config *ServerConfig

type ServerConfig struct {
	DBIP       string
	DBPort     string
	DBUser     string
	DBPassword string
	DBName     string
	TCPPort    string
	LogShowAll string
	Rlimit_cur uint64
	Rlimit_max uint64
	CacheSize  uint32
}

func NewConfig() *ServerConfig {
	config = new(ServerConfig)
	if config == nil {
		panic("config is nil")
	}

	data, err := ioutil.ReadFile(config_file)
	if err != nil {
		panic(err)
	}

	err = json.Unmarshal(data, config)
	if err != nil {
		panic(err)
	}
	return config
}
